<?php

class Zend_Controller_Action_Helper_User extends Zend_Controller_Action_Helper_Abstract {
	
	public function direct() {
		
	}
	
	/**
	 * Check if user is already loggin.
	 */
	public function isLoggedIn() {
		$storage = new Zend_Auth_Storage_Session();
		$data = $storage->read();
		return isset($data);
	}
	
	/**
	 * Check the given user info is same as the login session data.
	 * Then we can say this user is logged in
	 * 
	 * @param $user_id
	 * @return return true if given user has logged in
	 */
	public function userHasLoggedIn($user_id) {
		$hasLoggedIn = false;
		$storage = new Zend_Auth_Storage_Session();
		$data = $storage->read();
		if ($data->id == $user_id) {
			$hasLoggedIn = true;
		}
		return $hasLoggedIn;
	}
	
	/**
	 * Return user data from session.
	 */
	public function getUserData() {
		$storage = new Zend_Auth_Storage_Session();
		$data = $storage->read();
		return $data;
	}
	
	/**
	 * @param $user user
	 * @return return username if any, otherwise, return email
	 */
	public function getUserPresentName($user) {
		if (isset($user->username) || $user->username != '') {
			return $user->username;
		} else {
			return $user->email;
		}
		
	}
}
?>